(function(window,$,WebUploader){
	$(function(){
		var ctx=$.getCtx();
		var $images=$(".form-image-selector")
		$images.each(function(){
			var $this=$(this);
			var uploader = WebUploader.create({
			    swf: '../libs/webuploader/Uploader.swf',
			    server: ctx+'/system/resource/0',
			    pick: $this,
			    resize: false,
			    accept: {
		            title: 'Images',
		            extensions: 'gif,jpg,jpeg,bmp,png',
		            mimeTypes: 'image/jpg,image/jpeg,image/png'//解决谷歌打开文件选择慢的问题
		        },
		        chunked: false,
		        auto:true,
		        fileNumLimit: 1,
		        fileSizeLimit: 20 * 1024 * 1024,
		        fileSingleSizeLimit: 20 * 1024 * 1024
			});
			uploader.on('uploadError',function(file,reason){
				console.log(reason);
			});
			uploader.on('uploadSuccess',function(file,response){
				var id=response.id;
				$this.find("img").attr("src",ctx+'/system/resource/'+id);
				$this.find(".webuploader-pick").find("input").val(id);
			});
			uploader.on('uploadComplete',function(){
				uploader.reset();
			});
		});
	});
}(window,$,WebUploader))